package com.lmf.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lmf.eduservice.entity.EduCourse;
import com.lmf.eduservice.entity.EduSubject;
import com.lmf.eduservice.entity.EduTeacher;
import com.lmf.eduservice.service.EduCourseService;
import com.lmf.eduservice.service.EduSubjectService;
import com.lmf.eduservice.service.EduTeacherService;
import com.lmf.resultCode.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(description = "前台热门课程,名师管理器")
@CrossOrigin
@RestController
@RequestMapping("/eduservice/indexFront")
public class IndexFrontController {

    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduTeacherService eduTeacherService;

    @ApiOperation("根据查看次数，查询前8条热门课程，查询前4个名师")
    @GetMapping("/index")
    @Cacheable(key = "'selectHotCourseTeacher'",value = "HotCourseTeacher")
    public R index(){
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("view_count");
        wrapper.last("limit 8");
        List<EduCourse> eduCourses = eduCourseService.list(wrapper);

        QueryWrapper<EduTeacher> wrapper1 = new QueryWrapper<>();
        wrapper1.orderByDesc("id");
        wrapper1.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(wrapper1);
        return R.ok().data("courseList",eduCourses).data("teacherList",teacherList);
    }
}
